package com.sxfech.project.auth.controller;

import com.sxfech.project.auth.entity.LoginUser;
import com.sxfech.project.auth.repository.LoginUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class LoginUserController {
    @Autowired
    private LoginUserRepository loginUserRepository;
    @Autowired
    private PasswordEncoder passwordEncoder;

    @RequestMapping("/users/create")
    public Object create(LoginUser user) {
        System.out.println(user.getUsername());
        System.out.println(user.getPassword());
        user.setPassword(passwordEncoder.encode(user.getPassword()));
        user = loginUserRepository.save(user);
        return user;
    }

    @RequestMapping("/users/show")
    public Object show(HttpServletRequest request) {
        System.out.println("show....");
        return "show";
    }
}
